<cfcomponent extends="assets.csac.com.Base">

	<cffunction name="get" access="public" output="false" returntype="assets.csac.com.bo.Order">
		<cfargument name="Order_ID" type="string" required="true" />
		<cfscript>
			if (arguments.Order_ID gt 0) {
				local.args = {};
				local.args.obj = new assets.csac.com.bo.Order();
				StructAppend(local.args, QueryToStruct(read(argumentCollection = arguments))[1]);
				local.args.Deleted = 0;
				return load(argumentCollection = local.args);
			} else {
				return new assets.csac.com.bo.Order();
			}
		</cfscript>
	</cffunction>

	<cffunction name="load" access="public" output="false" returntype="assets.csac.com.bo.Order">
		<cfargument name="obj" type="assets.csac.com.bo.Order" required="true" />
		<cfscript>
			local.obj = arguments.obj;
			if (IsDefined("arguments.Order_ID")) {
				local.obj.setOrder_ID(arguments.Order_ID);
			}
			if (IsDefined("arguments.Order_UID")) {
				local.obj.setOrder_UID(arguments.Order_UID);
			}
			if (IsDefined("arguments.Approved_By_ID")) {
				local.obj.setApproved_By_ID(arguments.Approved_By_ID); 
			}
			if (IsDefined("arguments.Shipped_By_ID")) {
				local.obj.setShipped_By_ID(arguments.Shipped_By_ID); 
			}
			if (IsDefined("arguments.Deleted")) {
				local.obj.setDeleted(arguments.Deleted); 
			}
			if (IsDefined("arguments.Status")) {
				local.obj.setStatus(arguments.Status);
			}
			if (IsDefined("arguments.Order_Date")) {
				local.obj.setOrder_Date(arguments.Order_Date); 
			}
			if (IsDefined("arguments.Approved_Date")) {
				local.obj.setApproved_Date(arguments.Approved_Date); 
			}
			if (IsDefined("arguments.Shipped_Date")) {
				local.obj.setShipped_Date(arguments.Shipped_Date); 
			}
			if (IsDefined("arguments.Shipping_Instructions")) {
				local.obj.setShipping_Instructions(arguments.Shipping_Instructions);
			}
			if (IsDefined("arguments.Institution_ID")) {
				local.obj.setInstitution_ID(arguments.Institution_ID); 
			}
			if (IsDefined("arguments.Institution_Type")) {
				local.obj.setInstitution_Type(arguments.Institution_Type); 
			}
			if (IsDefined("arguments.Institution")) {
				local.obj.setInstitution(arguments.Institution); 
			}
			if (IsDefined("arguments.Department")) {
				local.obj.setDepartment(arguments.Department); 
			}
			if (IsDefined("arguments.Address1")) {                             
				local.obj.setAddress1(arguments.Address1);
			}
			if (IsDefined("arguments.Address2")) {                             
				local.obj.setAddress2(arguments.Address2);
			}
			if (IsDefined("arguments.City")) {
				local.obj.setCity(arguments.City);
			}
			if (IsDefined("arguments.State")) {
				local.obj.setState(arguments.State);
			}
			if (IsDefined("arguments.Zip_Code")) {
				local.obj.setZip_Code(arguments.Zip_Code);
			}
			if (IsDefined("arguments.First_Name")) {
				local.obj.setFirst_Name(arguments.First_Name); 
			}
			if (IsDefined("arguments.Last_Name")) {
				local.obj.setLast_Name(arguments.Last_Name); 
			}
			if (IsDefined("arguments.Email")) {
				local.obj.setEmail(arguments.Email); 
			}
			if (IsDefined("arguments.Phone")) {
				local.obj.setPhone(arguments.Phone); 
			}
			if (IsDefined("arguments.Extension")) {
				local.obj.setExtension(arguments.Extension); 
			}
			if (IsDefined("arguments.Shared_Notes")) {
				local.obj.setShared_Notes(arguments.Shared_Notes);
			}
			if (IsDefined("arguments.Private_Notes")) {
				local.obj.setPrivate_Notes(arguments.Private_Notes);
			}
			if (IsDefined("arguments.WMS_Order_ID")) {
				local.obj.setWMS_Order_ID(arguments.WMS_Order_ID);
			}
			if (IsDefined("arguments.Date_Created")) {
				local.obj.setDate_Created(arguments.Date_Created);
			}
			if (IsDefined("arguments.Order_Products")) {
				local.obj.setOrder_Products(arguments.Order_Products);
			}
			return local.obj;
		</cfscript>
	</cffunction>

	<cffunction name="read" access="public" output="false" returntype="any">
		<cfargument name="Order_ID" required="false" default="" />
		<cfargument name="Order_UID" required="false" default="" />
		<cfargument name="Approved_By_ID" required="false" default="" />
		<cfargument name="Shipped_By_ID" required="false" default="" />
		<cfargument name="Deleted" required="false" default="0" />
		<cfargument name="Status" required="false" default="" />
		<cfargument name="Order_Date" required="false" default="" />
		<cfargument name="Approved_Date" required="false" default="" />
		<cfargument name="Shipped_Date" required="false" default="" />
		<cfargument name="Shipping_Instructions" required="false" default="" />
		<cfargument name="Institution_ID" required="false" default="" />
		<cfargument name="Institution_Type" required="false" default="" />
		<cfargument name="Institution" required="false" default="" />
		<cfargument name="Department" required="false" default="" />
		<cfargument name="Address1" required="false" default="" />
		<cfargument name="Address2" required="false" default="" />
		<cfargument name="City" required="false" default="" />
		<cfargument name="State" required="false" default="" />
		<cfargument name="Zip_Code" required="false" default="" />
		<cfargument name="First_Name" required="false" default="" />
		<cfargument name="Last_Name" required="false" default="" />
		<cfargument name="Email" required="false" default="" />
		<cfargument name="Phone" required="false" default="" />
		<cfargument name="Extension" required="false" default="" />
		<cfargument name="Shared_Notes" required="false" default="" />
		<cfargument name="Private_Notes" required="false" default="" />
		<cfargument name="WMS_Order_ID" required="false" default="" />		
		<cfargument name="Date_Created" required="false" default="" />
		<cfargument name="orderIDs" required="false" default="" />
		<cfargument name="approverIDs" required="false" default="" />
		<cfargument name="shipperIDs" required="false" default="" />
		<cfargument name="institutionIDs" required="false" default="" />
		<cfargument name="statuses" required="false" default="" />
		<cfargument name="fromOrderDate" required="false" default="" />
		<cfargument name="toOrderDate" required="false" default="" />
		<cfargument name="fromApprovedDate" required="false" default="" />
		<cfargument name="toApprovedDate" required="false" default="" />
		<cfargument name="fromShippedDate" required="false" default="" />
		<cfargument name="toShippedDate" required="false" default="" />
		<cfargument name="institutionTypes" required="false" default="" />
		<cfargument name="wmsOrderIDs" required="false" default="" />
		<cfset var recs = "">
		<cfstoredproc datasource="#getDatasource()#" procedure="readOrder">
			<cfprocparam value="#arguments.Order_ID#" cfsqltype="CF_SQL_INTEGER" null="#IIf(Len(Trim(arguments.Order_ID)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Order_UID#" cfsqltype="CF_SQL_IDSTAMP" null="#IIf(Len(Trim(arguments.Order_UID)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Approved_By_ID#" cfsqltype="CF_SQL_INTEGER" null="#IIf(Len(Trim(arguments.Approved_By_ID)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Shipped_By_ID#" cfsqltype="CF_SQL_INTEGER" null="#IIf(Len(Trim(arguments.Shipped_By_ID)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Deleted#" cfsqltype="CF_SQL_BIT" null="#IIf(Len(Trim(arguments.Deleted)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Status#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.Status)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Order_Date#" cfsqltype="CF_SQL_DATE" null="#IIf(Len(Trim(arguments.Order_Date)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Approved_Date#" cfsqltype="CF_SQL_DATE" null="#IIf(Len(Trim(arguments.Approved_Date)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Shipped_Date#" cfsqltype="CF_SQL_DATE" null="#IIf(Len(Trim(arguments.Shipped_Date)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Shipping_Instructions#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.Shipping_Instructions)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Institution_ID#" cfsqltype="CF_SQL_INTEGER" null="#IIf(Len(Trim(arguments.Institution_ID)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Institution_Type#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.Institution_Type)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Institution#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.Institution)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Department#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.Department)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Address1#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.Address1)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Address2#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.Address2)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.City#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.City)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.State#" cfsqltype="CF_SQL_CHAR" null="#IIf(Len(Trim(arguments.State)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Zip_Code#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.Zip_Code)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.First_Name#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.First_Name)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Last_Name#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.Last_Name)) eq 0, true, false)#" />
			<cfprocparam value="#LCase(arguments.Email)#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.Email)) eq 0, true, false)#" />
			<cfprocparam value="#formatPhone(arguments.Phone)#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.Phone)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Extension#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.Extension)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Shared_Notes#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.Shared_Notes)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Private_Notes#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.Private_Notes)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.WMS_Order_ID#" cfsqltype="CF_SQL_INTEGER" null="#IIf(Len(Trim(arguments.WMS_Order_ID)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Date_Created#" cfsqltype="CF_SQL_TIMESTAMP" null="#IIf(Len(Trim(arguments.Date_Created)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.orderIDs#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.orderIDs)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.approverIDs#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.approverIDs)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.shipperIDs#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.shipperIDs)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.institutionIDs#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.institutionIDs)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.statuses#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.statuses)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.fromOrderDate#" cfsqltype="CF_SQL_DATE" null="#IIf(Len(Trim(arguments.fromOrderDate)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.toOrderDate#" cfsqltype="CF_SQL_DATE" null="#IIf(Len(Trim(arguments.toOrderDate)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.fromApprovedDate#" cfsqltype="CF_SQL_DATE" null="#IIf(Len(Trim(arguments.fromApprovedDate)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.toApprovedDate#" cfsqltype="CF_SQL_DATE" null="#IIf(Len(Trim(arguments.toApprovedDate)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.fromShippedDate#" cfsqltype="CF_SQL_DATE" null="#IIf(Len(Trim(arguments.fromShippedDate)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.toShippedDate#" cfsqltype="CF_SQL_DATE" null="#IIf(Len(Trim(arguments.toShippedDate)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.institutionTypes#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.institutionTypes)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.wmsOrderIDs#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.wmsOrderIDs)) eq 0, true, false)#" />
			<cfprocresult name="recs" />
		</cfstoredproc>
		<cfreturn recs />
	</cffunction>

	<cffunction name="save" access="public" output="false" returntype="any">
		<cfargument name="order" required="true" type="assets.csac.com.bo.Order" />
		<cfstoredproc datasource="#getDatasource()#" procedure="saveOrder">
			<cfprocparam value="#order.getOrder_ID()#" cfsqltype="CF_SQL_INTEGER" variable="id" type="inout" null="false" />
			<cfprocparam value="#order.getApproved_By_ID()#" cfsqltype="CF_SQL_INTEGER" null="#IIf(Len(Trim(order.getApproved_By_ID())) eq 0, true, false)#" />
			<cfprocparam value="#order.getShipped_By_ID()#" cfsqltype="CF_SQL_INTEGER" null="#IIf(Len(Trim(order.getShipped_By_ID())) eq 0, true, false)#" />
			<cfprocparam value="#order.getDeleted()#" cfsqltype="CF_SQL_BIT" null="false" />
			<cfprocparam value="#order.getStatus()#" cfsqltype="CF_SQL_VARCHAR" null="false" />
			<cfprocparam value="#order.getOrder_Date()#" cfsqltype="CF_SQL_DATE" null="false" />
			<cfprocparam value="#order.getApproved_Date()#" cfsqltype="CF_SQL_DATE" null="#IIf(Len(Trim(order.getApproved_Date())) eq 0, true, false)#" />
			<cfprocparam value="#order.getShipped_Date()#" cfsqltype="CF_SQL_DATE" null="#IIf(Len(Trim(order.getShipped_Date())) eq 0, true, false)#" />
			<cfprocparam value="#order.getShipping_Instructions()#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(order.getShipping_Instructions())) eq 0, true, false)#" />
			<cfprocparam value="#order.getInstitution_ID()#" cfsqltype="CF_SQL_INTEGER" null="false" />
			<cfprocparam value="#order.getInstitution_Type()#" cfsqltype="CF_SQL_VARCHAR" null="false" />
			<cfprocparam value="#order.getInstitution()#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(order.getInstitution())) eq 0, true, false)#" />
			<cfprocparam value="#order.getDepartment()#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(order.getDepartment())) eq 0, true, false)#" />
			<cfprocparam value="#order.getAddress1()#" cfsqltype="CF_SQL_VARCHAR" null="false" />
			<cfprocparam value="#order.getAddress2()#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(order.getAddress2())) eq 0, true, false)#" />
			<cfprocparam value="#order.getCity()#" cfsqltype="CF_SQL_VARCHAR" null="false" />
			<cfprocparam value="#order.getState()#" cfsqltype="CF_SQL_CHAR" null="false" />
			<cfprocparam value="#order.getZip_Code()#" cfsqltype="CF_SQL_VARCHAR" null="false" />
			<cfprocparam value="#order.getFirst_Name()#" cfsqltype="CF_SQL_VARCHAR" null="false" />
			<cfprocparam value="#order.getLast_Name()#" cfsqltype="CF_SQL_VARCHAR" null="false" />
			<cfprocparam value="#LCase(order.getEmail())#" cfsqltype="CF_SQL_VARCHAR" null="false" />
			<cfprocparam value="#formatPhone(order.getPhone())#" cfsqltype="CF_SQL_VARCHAR" null="false" />
			<cfprocparam value="#order.getExtension()#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(order.getExtension())) eq 0, true, false)#" />
			<cfprocparam value="#order.getShared_Notes()#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(order.getShared_Notes())) eq 0, true, false)#" />
			<cfprocparam value="#order.getPrivate_Notes()#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(order.getPrivate_Notes())) eq 0, true, false)#" />
			<cfprocparam value="#order.getWMS_Order_ID()#" cfsqltype="CF_SQL_INTEGER" null="#IIf(Len(Trim(order.getWMS_Order_ID())) eq 0, true, false)#" />
		</cfstoredproc>
		<cfreturn id />
	</cffunction>

	<cffunction name="destroy" access="public" output="false" returntype="any">
		<cfargument name="Order_ID" required="true" />
		<cfstoredproc datasource="#getDatasource()#" procedure="destroyOrder">
			<cfprocparam value="#arguments.Order_ID#" cfsqltype="CF_SQL_INTEGER" null="false" />
		</cfstoredproc>
		<cfreturn true />
	</cffunction>

</cfcomponent>

